/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Service;

import DAO.DAO;
import DAO.IEventDaoImpl;
import java.awt.Color;
import java.awt.Point;
import java.util.Date;
import java.util.List;
import javabeans.Event;
import javabeans.EventType;
import javabeans.GroupPlan;
import javabeans.Member;
import javabeans.Plan;

/**
 *
 * @author liweijiao
 */
public class EventServiceImpl implements EventService {

    IEventDaoImpl eventdao = new IEventDaoImpl();

    public Event newEvent(String ename, String etype, String eventdate, String eventtime, String edescript, double x, double y, String color, Plan plan) {
        Event event = new Event();
        event.setEventname(ename);
        event.setType(etype);
        event.setEventdate(eventdate);
        System.out.println("new event in EventServiceImpl: " + eventdate);
        event.setEventtime(eventtime);
        event.setEventdescript(edescript);
        event.setPointX(x);
        event.setPointY(y);
        event.setColor(color);
        event.setPlan(plan);
        if (eventdao.newEvent(event) != null) {
            DAO.close();
            return event;

        } else {
            DAO.close();
            return null;

        }
    }

    public Event modifyEvent(int eid, String ename,String etype, String eventdate, String eventtime, String edescript, double x, double y, String c, Plan plan) {
        Event event = eventdao.getEvent(eid);
        event.setEventname(ename);
        event.setType(etype);
        event.setEventdate(eventdate);
    System.out.println("modify event in EventServiceImpl: " + eventdate);
        event.setEventtime(eventtime);
        event.setEventdescript(edescript);
        event.setPointX(x);
        event.setPointY(y);
        event.setColor(c);
        event.setPlan(plan);
        if (eventdao.updateEvent(event) != null) {
            DAO.close();
            return event;
        } else {
            DAO.close();
            return null;
        }
    }

    public boolean deleteEvent(int eventid, int planid) {
        Event event = eventdao.getEvent(eventid);
        if (eventdao.deleteEvent(event)) {
            DAO.close();
            return true;
        } else {
            DAO.close();
            return false;
        }


    }



    public List<Event> getEventList(int planid) {
       List<Event> el=eventdao.getEventList(planid);
        if(el !=null)
        {   DAO.close();
            return el;
        }
        else
        {
           DAO.close();
           return null;
        }
    }

    public Event newGroupEvent(String ename, String etype, String eventdate, String eventtime, String edescript, double x, double y, String color, GroupPlan groupplan) {
         Event event = new Event();
        event.setEventname(ename);
        event.setType(etype);
        event.setEventdate(eventdate);
        event.setEventtime(eventtime);
        event.setEventdescript(edescript);
        event.setPointX(x);
        event.setPointY(y);
        event.setColor(color);
        event.setGroupplan(groupplan);
        if (eventdao.newEvent(event) != null) {
            DAO.close();
            return event;

        } else {
            DAO.close();
            return null;

        }
    }

    public Event modifyGroupEvent(int eid, String ename, String etype, String eventdate, String eventtime, String edescript, double x, double y, String c, GroupPlan groupplan) {
      Event event = eventdao.getEvent(eid);
        event.setEventname(ename);
        event.setType(etype);
        event.setEventdate(eventdate);
        event.setEventtime(eventtime);
        event.setEventdescript(edescript);
        event.setPointX(x);
        event.setPointY(y);
        event.setColor(c);
        event.setGroupplan(groupplan);
        if (eventdao.updateEvent(event) != null) {
            DAO.close();
            return event;
        } else {
            DAO.close();
            return null;
        }
    }

    public boolean deleteGroupEvent(int eventid, int groupplanid) {
       Event event = eventdao.getEvent(eventid);
        if (eventdao.deleteEvent(event)) {
            DAO.close();
            return true;
        } else {
            DAO.close();
            return false;
        }
    }

    public List<Event> getGroupEventList(int groupplanid) {
        List<Event> el=eventdao.getGroupEventList(groupplanid);
        if(el !=null)
        {   DAO.close();
            return el;
        }
        else
        {
           DAO.close();
           return null;
        }
    }
}
